import router from '@/router'
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'


export const useRouteStore = defineStore('routes', () => {
    const routes = ref([{
        path: '/dashboard',
        name: 'dashboard',
        meta: {
            title: '首页',
            icon: 'House'
        }
    }])



    const addRoutes = (route) => {
        const findIndexResult = routes.value.findIndex(item => item.name === route.name)
        findIndexResult >= 0 ? routes.value[findIndexResult].path = route.fullPath : ''

        if (findIndexResult < 0) routes.value.push(route)
    }


    /**
     * @description: 删除某个路由信息,用于子页面跳转时删除子页面路由
     * @param {*} route：需要删除的路由信息
     */
    const deleteRoute = (route) => {
        const index = routes.value.findIndex(item => item.name === route.name)
        routes.value.splice(index, 1)
    }

    const resetRoutes = () => {
        routes.value = [{
            path: '/dashboard',
            name: 'dashboard',
            meta: {
                title: '首页',
                icon: 'House'
            }
        }]
    }

    return { routes, addRoutes, resetRoutes, deleteRoute }
})